define(['common','clipboard'], function(common,ClipboardJS){
    //清空内容
    $(document).on('click', '.btn-trash', function(){
        $($(this).data('target')).val('');
    });
    //测试内容
    $(document).on('click', '#btn-test', function(){
        $($(this).data('target')).val($(this).data('content'));
    });
    //复制按钮
    var clipboard = new ClipboardJS('.btn-copy');
    clipboard.on('success',function(e){
        common.toastMini('复制完成',1000);
    });
    //打开链接
    $(document).on('click', '#btn-video,#btn-audio', function(){
        var $href = $($(this).data('target')).val();
        if($href){
            $(this).attr('href',$href);
        }else{
            common.toastMini('下载链接不能为空');
            return false;
        }
    });
    //解析作品
    $(document).on('submit', '#parse', function(){
        $.ajax({
            type: "POST",
            url: $(this).attr('action'),
            data: $(this).serialize(),
            beforeSend: function(xhr){
                $('.icon-loading').removeClass('hidden');
                $('#text').html('');
            },
            success: function(result, status, xhr){
                if(result.code==1){
                    $('#desc').text(result.data.desc);
                    $('#text').val(result.data.text.join("\n"));
                    $('#result').fadeIn();
                }else{
                    common.location(result.url);
                    common.toastMini(result.msg);
                }
            },
            complete:function(xhr, status){
                $('.icon-loading').addClass('hidden');
            }
        });
        return false;
    });
    //返回结果
    return true;
});